<?php


namespace app\api\controller;


use app\Request;
use think\facade\Db;
class Chat extends Api
{

    //查询聊天记录
    public function getchatmsglist(Request $request){
        if (!$request->isPost()) $this -> error("请求方式错误");
        $uid = $request->post('uid');
        $accessToken = $request->post('token');
        $roomnumber = $request->post('roomnumber');
        $pageSize = $request->post('pageSize') ?? 5;
        $page = $request->post('pageNo');

        if ($accessToken == '' || $uid == '' || $roomnumber == '') $this -> error('参数错误');
        $this -> check_token($accessToken);
        $starttime = date("Y-m-d H:i:s",strtotime('last day this week'));
        $endtime = date("Y-m-d H:i:s",time()-1*60);
        $where = "roomnumber = '$roomnumber' and sendtime >= UNIX_TIMESTAMP( '".$starttime."') and sendtime <= UNIX_TIMESTAMP( '".$endtime."' )";
        if($page == 0){
            $reslist = [];
        }else{
            $pages = ($page - 1) * $pageSize;
            $reslist = Db::name('roommsg')
                -> where($where)
                -> order('id desc')
//            -> field('id,title,images,price,sales')
                -> limit($pages,$pageSize)
                -> select() ->toArray();
            //        echo Db::name('roommsg') -> getLastSql();die;
            $last_names = array_column($reslist,'id');
            array_multisort($last_names,SORT_ASC,$reslist);
        }
        $this->success('请求成功',$reslist);
    }



    //获取聊天信息


}